import 'package:bike_ride/common/util/hysize_fit.dart';
import 'package:bike_ride/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_picker_plus/flutter_picker_plus.dart';


class PickerTool {
  static Widget _titleWidget(String title) => Text(title,
      style: TextStyle(
          color: Colors.black.withOpacity(0.9),
          fontSize: 34.rpx,
          fontWeight: FontWeight.bold));
  //未选中item颜色
  static final TextStyle _textStyle = TextStyle(
      color: Colors.black.withOpacity(0.9),
      fontSize: 32.rpx,
      fontWeight: FontWeight.w400);

  static final TextStyle _cancelTextStyle = TextStyle(
      color: Colors.black.withOpacity(0.6),
      fontSize: 32.rpx,
      fontWeight: FontWeight.w400);

  static TextStyle _confirmTextStyle(context) => TextStyle(
      color: Theme.of(context).colorScheme.primary,
      fontSize: 32.rpx,
      fontWeight: FontWeight.w400);

  static final TextStyle _selectedTextStyle = TextStyle(
      color: Colors.black.withOpacity(0.9),
      fontSize: 32.rpx,
      fontWeight: FontWeight.w400);

  static void showStringPicker(BuildContext context, List<String?> data,
      {String? title,
      List<int>? selecteds,
      List<PickerItem>? adapter,
      Function? handleCancel,
      Function? handleConfirm}) {
    title??=S.current.pleaseSelect;
    Picker(
        backgroundColor: Colors.white,
        containerColor: Colors.white,
        adapter: adapter as PickerAdapter<dynamic>? ??
            PickerDataAdapter<String>(pickerData: data, isArray: false),
        cancelText: S.current.cancel,
        confirmText: S.current.confirm,
        selecteds: selecteds ?? [0],
        headerDecoration: const BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(
              width: 1,
              color: Color(0xffE7E7E7),
            ),
          ),
        ),
        height: 400.rpx,
        itemExtent: 80.rpx,
        title: _titleWidget(title),
        textStyle: _textStyle,
        cancelTextStyle: _cancelTextStyle,
        confirmTextStyle: _confirmTextStyle(context),
        selectedTextStyle: _selectedTextStyle,
        onConfirm: (Picker picker, List value) {
          if (handleConfirm != null) {
            handleConfirm(value);
          }
        },
        onCancel: () {
          if (handleCancel != null) {
            handleCancel();
          }
        }).showModal(context);
  }

}
